using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using Commons;
using WPFBPMN;

namespace CustomControls
{
    /// <summary>
    /// InterID logic for BPMNContainer.xaml
    /// </summary>

    public partial class BPMNContainer : BPMNShape
    {

        #region Fields

        Label title = new Label();
        BPMNShape drawingCanvas;

        #endregion

        #region Properties

        public override UIElementCollection Children
        {
            get
            {
                if (drawingCanvas != null)
                {
                    return drawingCanvas.Children;
                }
                return null;
            }
        }

        public Label Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }

        public BPMNShape DrawingCanvas
        {
            get
            {
                return drawingCanvas;
            }
            set
            {
                drawingCanvas = value;
            }
        }

        public new StartMouseDownInformation StartInfo
        {
            get { return new StartMouseDownInformation(); }
            set
            {
            }

        }

        #endregion

        #region Constructor

        public BPMNContainer(BPMNShape parent)
            : base(parent)
        {
            ShapeDefaultSize = new Size(100, 100);
            drawingCanvas = new BPMNShape(this);
            WrapPanel panel = new WrapPanel();
            title.LayoutTransform = new RotateTransform(-90);
            title.Height = 50;
            Binding binding = new Binding();
            binding.Source = this;
            binding.Path = new PropertyPath(BPMNShape.BPMNNameProperty);
            title.SetBinding(Label.ContentProperty, binding);
            panel.Children.Add(title);
            drawingCanvas.Background = Brushes.White;
            panel.Children.Add(drawingCanvas);
            Canvas.SetTop(panel, 1);
            Canvas.SetLeft(panel, 1);
            (this as Canvas).Children.Add(panel);
            this.Background = Brushes.White;
        }

        #endregion

        #region Methods



        public override void PositionShapeOnCreate(BPMNShape drawing, MouseButtonEventArgs e)
        {
            Canvas.SetLeft(drawing, Canvas.GetLeft(drawing) - title.Height);
            drawing.UpdateConnectingPoints();
        }

        public override void ResizeShape()
        {
            base.ResizeShape();
            //drawingCanvas.Width = Width - title.Height-2;
            for (int i = 0; i < Children.Count; i++)
            {
                BPMNShape s = Children[i] as BPMNShape;
                if (s != null)
                {
                    if (Canvas.GetLeft(s) > DrawingCanvas.Width)
                    {
                        s.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        s.Visibility = Visibility.Visible;
                    }
                }
            }
        }

        #endregion

        #region BPMNShape Members

        new BPMNShape CurrentWorkingElement
        {
            get
            {
                throw new Exception("The method or operation is not implemented.");
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");

            }
        }

        new BPMNShape CurrentSelectedElement
        {
            get
            {
                throw new Exception("The method or operation is not implemented.");
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        #endregion

    }
}